package com.pig4cloud.pigx.robot.ws.collect.bitmex;


import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public class ParseData {

	public static String source_name = "bitmex";
	public static void parse(String msg){
		try{
			JSONObject json = JSONObject.parseObject(msg).getJSONArray("data").getJSONObject(0);
			if(json!= null){
				if(json.get("markPrice") != null){
					String symbol = json.getString("symbol").toUpperCase();
					if(symbol.indexOf("XBT") > 0){
						symbol = "BTCUSDT";
					}
					//标记价格
					String k_mark = "robot_bitmex_markprice_" + symbol;
					Date dt =  json.getDate("timestamp");

					String v_mark =json.getString("markPrice") + "_" + dt.getTime();

					WsManager.getInstance().fetchManager.setdata(k_mark,v_mark);
				}
			}

		}catch (Exception ex){
			log.error("parse bitmex data error  "+ex.getMessage());
		}
	}

}
